$(function () {
    layui.use(['form','laydate', 'layer','jquery'],
        function() {
            $ = layui.jquery;
            let form = layui.form,
                layer = layui.layer;

            //自定义验证规则
            form.verify({
                name: function(value) {
                    if (value.length < 2) {
                        return '产品类别名称至少两个字符';
                    }
                }
            });

            //监听提交
            form.on('submit(add)', function(data) {
                data = data.field;

                $.ajax({
                    url: 'http://127.0.0.1:8080/back/device_class/add',
                    data: data,
                    type: 'post',
                    dataType: 'json',
                    success: function (res) {
                        if (res.count > 0) {
                            layer.alert("新增成功", {
                                    icon: 6
                                },
                                function () {
                                    //关闭当前frame
                                    xadmin.close();

                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        } else {
                            layer.alert("新增失败"+res.msg);
                        }
                    }
                })
                //发异步，把数据提交给java

                return false;
            });

        });
})